package com.base.cn.platform.os.controller.marketing.baseShare;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.constants.ConfigName;
import com.base.cn.platform.os.service.manage.config.SysConfigService;
import com.base.cn.platform.os.service.manage.marketing.baseShare.MarketingBaseShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;

/**
 * 后台分享海报Controller
 *
 * @since 2019/4/17
 */
@Controller
@RequestMapping("/admin/marketing")
public class AdminMarketingBaseShareController extends AdminBaseController {

    @Autowired
    private MarketingBaseShareService marketingBaseShareService;
    @Autowired
    private SysConfigService sysConfigService;
    /**
     * 分享海报配置
     *
     * @param model
     * @return
     */
    @RequestMapping("/baseShare")
    public String queryBaseShare(Model model){

        Map<String,Object> params = new HashMap<>();
        Map<String,Object> baseShare = marketingBaseShareService.queryBaseShare(params);
        model.addAttribute("baseShare",baseShare);
        TreeMap<String,String> configMap = sysConfigService.getSysConfigContext(ConfigName.H5AMOBILE);
        model.addAttribute("configMap",configMap);
        return resultPage("/marketing/baseShare/base-share");
    }

    /**
     * 保存海报分享数据
     *
     * @param params
     * @return
     */
    @RequestMapping("/saveBaseShare")
    @ResponseBody
    public Map<String, Object> saveBaseShare(@RequestBody Map<String,Object> params) {
        return marketingBaseShareService.saveBaseShare(params);
    }

}
